<?php

namespace backend\models\course;

use Yii;

/**
 * This is the model class for table "{{%edu_course_category}}".
 *
 * @property integer $cate_id
 * @property string $cate_name
 * @property integer $cate_addtime
 * @property integer $cate_sort
 * @property integer $is_show
 */
class CourseCategory extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%course_category}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['cate_name'], 'required'],
            [['cate_addtime', 'cate_sort', 'is_show'], 'integer'],
			[ 'cate_addtime','default', 'value' =>time(),],
            [['cate_name'], 'string', 'max' => 100]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'cate_id' => '类别ID',
            'cate_name' => '类别名称',
            'cate_addtime' => '添加时间',
            'cate_sort' => '类别排序',
            'is_show' => '是否显示',
        ];
    }
	/**
	* 显示分类
	*/
	public function selcate()
    {
		return $this->find()
					->orderBy(['cate_sort'=>SORT_DESC])
					->all();
	}
	/**
	* 前台显示分类
	*/
	public function Cate()
    {
		return $this->find()
					->where(['is_show' => 1])
					->orderBy(['cate_sort'=>SORT_DESC])
					->all();
	}
}
